package logic

import (
	"context"
	"douban/models/mysql"

	"douban/doubanrpc/doubanrpc"
	"douban/doubanrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartListLogic {
	return &CartListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartListLogic) CartList(in *doubanrpc.CartListRequest) (*doubanrpc.CartListResponse, error) {
	// todo: add your logic here and delete this line

	var cart []mysql.Cart
	mysql.DB.Debug().Find(&cart)
	var cartList []*doubanrpc.CartList
	for _, m := range cart {
		list := doubanrpc.CartList{
			Id:        int64(m.ID),
			UserId:    m.UserId,
			ProductId: m.ProductId,
			Quantity:  m.Quantity,
		}
		cartList = append(cartList, &list)
	}
	return &doubanrpc.CartListResponse{
		List: cartList,
	}, nil
}
